package unit03.day03;

import java.util.Calendar;

/**
 * Calendar提供了针对不同时间分量单独设置值的方法
 * void set(int field,int value)
 * 其中第一个参数为:时间分量，例如：年，月，日等
 * 第二个参数为对应的值
 * 时间分量是一个int值，使用Calendar提供的常量
 * */
public class CalendarDemo2 {

	public static void main(String[] args) {
		Calendar calendar = Calendar.getInstance();
		//设置表示2008-08-08 20:08:08
		//设置年、月
		calendar.set(Calendar.YEAR, 2008);
		calendar.set(calendar.MONTH, 7);
		/**
		 * 设置天
		 * DATE:月中天
		 * DAY_OF_MONTH:月中天，与DATE一致
		 * DAY_OF_WEEK:周中的天，星期几
		 * DAY_OF_YEAR:年中的天
		 * */
		calendar.set(calendar.DAY_OF_MONTH, 8);
		calendar.set(calendar.HOUR_OF_DAY, 8);
		calendar.set(calendar.MINUTE, 8);
		calendar.set(calendar.SECOND, 8);
		System.out.println(calendar.getTime());
		
		//获取时间
		int year = calendar.get(Calendar.YEAR);
		int month = calendar.get(Calendar.MONTH) + 1;
		int day = calendar.get(Calendar.DAY_OF_MONTH);
		int hour = calendar.get(Calendar.HOUR_OF_DAY);
		int minute = calendar.get(Calendar.MINUTE);
		int scond = calendar.get(Calendar.SECOND);
		
		//查看星期几
		int dow = calendar.get(Calendar.DAY_OF_WEEK - 1);
		String[] data = {"日","一","二","三","四","五","六"};
		
		//到今天为止，今年过了多少天
		int dow1 = calendar.get(Calendar.DAY_OF_YEAR - 1);
		System.out.println("星期"+data[dow - 1]);
		System.out.println(year+"-"+month+"-"+day+" "+hour+":"+minute+":"+scond);
	}
}
